import { Comm } from "../utils/common.js";
class Topic extends Comm {
    constructor() {
        super();
        this.getListData = {
            Page: 1,
            PageSize: 5,
            categoryId: 0,
            keyword:""
        }
        this.getHotData = {
            Page: 1,
            PageSize: 10,
        }
        this.searchData = {
            Page: 1,
            PageSize: 10,
            keyword:""
        }
    };
    /**
     * 请求帖子的分类
     */
    getCategoryList() {
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/category/list",
                type: "GET",
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 请求帖子列表
     */
    getTopicList(options) {
        this.getListData.Page = options.type == "first" ? 1 : this.getListData.Page + 1;
        this.getListData.categoryId = options.categoryId;
        this.getListData.keyword = options.keyword;
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/post/list",
                type: "GET",
                data: this.getListData,
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 请求帖子详情
     */
    getDetail(id) {
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/post/get",
                type: "GET",
                data: {
                    postId: id
                },
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 帖子投票
     * options = {
     *    postId:1,
     *    voteId:1
     * }
     */
    vote(options) {
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/post/vote",
                data: options,
                type: "POST",
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 帖子点赞
     */
    like(options) {
        const url = options.type == "like" ? "/gateway/api/post/like" : "/gateway/api/post/unlike"
        return new Promise((resolve, reject) => {
            let props = {
                url: url,
                type: "POST",
                data: {
                    postId: options.id
                },
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        })
    };
    /**
     * 帖子关注
     */
    follow(options) {
        const url = options.type == "follow" ? "/gateway/api/post/follow" : "/gateway/api/post/unfollow"
        return new Promise((resolve, reject) => {
            let props = {
                url: url,
                type: "POST",
                data: {
                    postId: options.id
                },
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        })
    };
    /**
     * 帖子删除
     */
    delete(id) {
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/post/delete",
                type: "POST",
                data: {
                    postId: id
                },
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 发布帖子
     */
    publish(options) {
        return new Promise((resolve, reject) => {
            let props = {
                url: "/gateway/api/post/create",
                type: "POST",
                data: options,
                sCallBack: res => {
                    resolve(res);
                },
                eCallBack: err => {
                    reject(err);
                }
            }
            this.request(props);
        });
    };
    /**
     * 十大热帖
     */
    getHotTopic(options){
      this.getHotData.Page = options.type == "first" ? 1 : this.getHotData.Page + 1;
      return new Promise((resolve, reject) => {
        let props = {
          url: "/gateway/api/post/hot",
          type: "GET",
          data: this.getHotData,
          sCallBack: res => {
            resolve(res);
          },
          eCallBack: err => {
            reject(err);
          }
        }
        this.request(props);
      });
    };
}

export { Topic }